﻿using Castle.DynamicProxy;
using ManYan.Application;
using ManYan.Common.Intercept;
using ManYan.Domain.DomainService;
using ManYan.Domain.Model.Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Linq.Expressions;
using System.Reflection;

namespace ManYan.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class InterceptController : ControllerBase
    {
        IBaseDomainService<tb_user_refresh_token> _baseAppService;
        public InterceptController(IBaseDomainService<tb_user_refresh_token> baseAppService, IHttpContextAccessor httpContextAccessor)
        {
            _baseAppService = baseAppService;
        }
        [HttpDelete]
        public int Delete(Guid id)
        {
            FilterIntercept filterIntercept = new FilterIntercept();
            ProxyGenerator proxyGenerator = new ProxyGenerator();
           // return _baseAppService.DelEntity(x => x.Id == id);

            IBaseAppService<tb_user_refresh_token> intercept = proxyGenerator.CreateInterfaceProxyWithTarget<IBaseAppService<tb_user_refresh_token>>(new ManYan.Application.BaseAppService<tb_user_refresh_token>(_baseAppService), filterIntercept);

            intercept.LoadEntityAll();

            return intercept.DelEntity(x => x.Id == id);

          //  return _baseAppService.DelEntity(x => x.Id == id);

            // System.Linq.Expressions.Expression<Func<tb_exam_content, bool>> expression = x => x.Id == id;
            //throw new Exception("");
        }
    }
}
